package io.renren.controller;

import io.renren.common.utils.R;
import io.renren.common.utils.RandomUtil;
import io.renren.common.utils.UrlReqUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.FileNameMap;
import java.net.URLConnection;
import java.util.List;

@RestController
@RequestMapping("api/file")
@CrossOrigin(origins = "*", maxAge = 3600)
public class FileController {

    @RequestMapping("/uploadfile")
    public R uploadFile(HttpServletRequest request, HttpServletResponse response) {
        String img = null;

        try {
            img = UrlReqUtil.isContainsIMG(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok().put("url",img);
    }

    @RequestMapping("/uploadfile2")
    public R uploadFile2(HttpServletRequest request, HttpServletResponse response) {
        String img = null;
        try {
            img = UrlReqUtil.isContainsVideo(request);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok().put("url",img);
    }


    @RequestMapping("/savefiles")
    private List<String> saveFiles(HttpServletRequest request, HttpServletResponse response) {
        List<String> list = null;
        try {
            list = UrlReqUtil.isContainsIMGS(request);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
}